package HashTable;

import java.util.HashMap;
import java.util.Map;

public class _290_WordPattern {
    public boolean wordPattern(String pattern, String str) {
        Map<Character, String> maps = new HashMap<Character, String>();
        String[] words = str.split(" ");
        if (pattern.length() != words.length) {
            return false;
        }
        int count = 0;
        for (char c : pattern.toCharArray()) {
            if (maps.containsKey(c)) {
                if (!maps.get(c).equals(words[count])) {
                    return false;
                }
            } else {
                if (maps.containsValue(words[count])) {
                    return false;
                }
                maps.put(c, words[count]);
            }
            count++;
        }
        return true;
    }
}
